<template>
    <!--左侧房源筛选-->
    <div class="lefMain">
        <!--左侧1-->
        <span class="leftTop">
            <span style="font-size: 18px;white-space: nowrap;color:#7a8df1;font-weight: 600;">{{ $t('text.Contract.l95')
            }}</span>
            <span class="df" @click="this.$router.push('/addEmployees')">
                <img class="addImg" src="../../assets/images/add.svg">
                <div style="font-size: 13px;white-space: nowrap;">{{ $t('text.Contract.l65') }}</div>
            </span>
        </span>

        <!--左侧3-->
        <div>
            <div class="leftTop2">

                <div class="df">
                    <img class="img2" src="../../assets/images/icon.png" />
                    <div class="time">
                        {{ $t('text.Contract.l96') }}
                        <el-date-picker v-model="time" type="month" :placeholder="$t('text.Employee.l26')"
                            style="width: 100px;margin-left: 10px;height: 23px;font-size: 12px;" value-format="YYYY-MM" />
                    </div>
                </div>

            </div>
        </div>
        <div class="resetDiv" @click="reset">{{ $t('text.Contract.l32') }}</div>

    </div>

    <!--右侧房源列表-->
    <div class="rightMain">
        <!--右侧顶部导航-->
        <div class="rightTop">
            <div></div>
            <TimePageNavList :timeNavList="timeNavList.data" :defaultClick="timeNavList.defaultClick"
                @returnData="setHouseType"></TimePageNavList>
            <div class="out"><img class="outImg" src="../../assets/images/out.svg"><span>{{ $t('text.Employee.l7') }}</span>
            </div>
        </div>
        <!--右侧房源数据列表-->
        <div class="rightContain">

            <table class="rightList" v-if="resultList.length > 0">
                <tr class="eDataList dataHead">
                    <td class="dataDom" v-for="(item,index) in dataTitleList" v-bind:key="item"
                        :style="index == 0? { flex: 1.2 } : {}">{{ item }}</td>
                </tr>
                <tr class="eDataList" v-for="item in resultList" v-bind:key="item">
                    <td class="dataDom" style="flex: 1.2;">
                        <div class="dataTitle">
                            <CommonOmit :text="item.orgName == null ? '-' : item.orgName" :length="1"></CommonOmit>
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            {{ item.month == null ? '-' : item.month }}
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            {{ item.mustPrice == null ? '-' : item.mustPrice }}
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            {{ item.realPrice == null ? '-' : item.realPrice }}
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle" :style="item.orgCost > 0 ? { color: '#f68686' } : { color: '#54d2d0' }">
                            {{ item.orgCost == null ? '-' : item.orgCost }}
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle" :style="item.userReward > 0 ? { color: '#f68686' } : { color: '#54d2d0' }">
                            {{ item.userReward == null ? '-' : item.userReward }}
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            {{ item.userSalary == null ? '-' : item.userSalary }}
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            {{ item.userComm == null ? '-' : item.userComm }}
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle" :style="item.profit > 0 ? { color: '#f68686' } : { color: '#54d2d0' }">
                            {{ item.profit == null ? '-' : item.profit }}
                        </div>
                    </td>
                </tr>
            </table>
            <div class="rightList" v-else>
                <div class="nulData">
                    {{ $t('text.Common.l67') }}
                </div>
            </div>
            <!--底部分页-->
            <div class="setPage">
                <el-pagination v-model:current-page="searchData.pageNo" v-model:page-size="searchData.pageSize"
                    :page-sizes="[10, 15, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper" :total="total"
                    @size-change="handleSizeChange" @current-change="handleCurrentChange" />
            </div>
        </div>
    </div>
</template>
    
<script>
import CommonOmit from "@/components/input/CommonOmit.vue"
import { accountsFindPage } from "../../http/api"
export default {
    name: "CollectionRecords",
    components: { CommonOmit },
    data() {
        return {
            searchData: {
                pageNo: 1,
                pageSize: 15,
                orgLevel: 3
            },
            time: '',
            timeNavList: {
                defaultClick: this.$t("text.Contract.l98"),
                data: [this.$t("text.Contract.l98"), this.$t("text.Contract.l99"), this.$t("text.Contract.l100")],
            },
            dataTitleList: [
                this.$t("text.Contract.l101"), this.$t("text.Contract.l102"), this.$t("text.Contract.l103"),
                this.$t("text.Contract.l104"), this.$t("text.Contract.l105"), this.$t("text.Contract.l106"),
                this.$t("text.Contract.l107"), this.$t("text.Contract.l108"), this.$t("text.Contract.l109"),
            ],
            resultList: [],
            total: 0,
        }
    },
    mounted() {
        this.search()
    },
    methods: {

        //搜索数据
        search() {
            accountsFindPage(this.searchData).then(res => {
                if (res !== undefined) {
                    this.resultList = res.dataList
                    this.total = res.total
                    console.log(res)
                }
            })
        },

        //拼接单个子组件返回来的条件值
        setData(obj) {
            this.searchData = { ...this.searchData, ...obj }
            console.log(JSON.stringify(this.searchData))
        },

        //子组件选择了不限，进行删除指定字段
        clearData(obj) {
            const objKeys = Object.keys(obj)
            this.searchData = Object.keys(this.searchData).reduce((acc, key) => {
                if (!objKeys.includes(key)) {
                    acc[key] = this.searchData[key]
                }
                return acc
            }, {})
            console.log(JSON.stringify(this.searchData))
        },
        setHouseType(type) {
            switch (type) {
                case 0: this.searchData = { pageNo: 1, pageSize: 15, orgLevel: 3 }; this.time = ''; break;
                case 1: this.searchData = { pageNo: 1, pageSize: 15, orgLevel: 2 }; this.time = ''; break;
                case 2: this.searchData = { pageNo: 1, pageSize: 15, orgLevel: 1 }; this.time = ''; break;
            }
            console.log(type)
        },
        //重置
        reset() {
            this.time = ''
        },
        handleSizeChange(val) {
            this.searchData.pageSize = val
            this.search()
        },
        handleCurrentChange(val) {
            this.searchData.pageNo = val
            this.search()
        },
    },
    watch: {
        searchData: {
            handler() {
                this.search()
            },
        },
        time() {
            if (this.time == null) {
                this.clearData({ month: "" })
            } else {
                let obj = { month: this.time }
                this.searchData = { ...this.searchData, ...obj }
            }
        },
    },
    computed: {},
}
</script>
    
<style scoped>
.nulData {
    background-image: url("../../assets/images/nullData.svg");
    background-size: cover;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 25px;
    color: #979797;
}

.resetDiv {
    background: #6698ff;
    margin-top: 20px;
    padding: 5px 0;
    font-size: 13px;
    color: white;
    border-radius: 7px;
}

.df {
    display: flex;
    align-items: center;
    margin-top: 8px;
    margin-bottom: 2px;
}

.lefMain {
    min-width: 310px;
    padding: 15px;
    overflow: auto;
    background: white;
    margin-bottom: 30px;
    margin-right: 5px;
    box-shadow: 1px 10px 30px 4px #e9e9e9;
}

.rightContain {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    background: white;
    margin: 20px 30px 30px 25px;
    position: relative;
    box-shadow: 1px 5px 10px 4px #e9e9e9;
}

.leftTop {
    color: #6698ff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.leftTop2 {
    border: 1px solid #cecece;
    border-radius: 5px;
    padding: 10px;
    margin-top: 10px;
    position: relative;
    padding-top: 0;
}

.img2 {
    width: 22px;
    height: 22px;
}

.items {
    margin-left: 15px;
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 12px;
    color: gray;
    border-bottom: 1px solid rgb(224, 224, 224);
    width: 100%;
}

.rightMain {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #f8f8f8;
}

.rightList {
    height: 100%;
    display: flex;
    flex-direction: column;
    border-radius: 5px;
    overflow: auto;
    padding: 20px 0;
    padding-top: 0;
}

.rightTop {
    display: flex;
    padding-top: 15px;
    align-items: center;
    justify-content: space-between;
    padding-right: 32px;
}

.addImg {
    width: 15px;
    height: 15px;
    padding-right: 3px;
}

.setPage {
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid #eee;
    padding: 10px;
}

.out {
    display: flex;
    align-items: center;
    font-size: 14px;
}

.outImg {
    width: 20px;
    height: 20px;
    padding-right: 5px;
}

.img2 {
    width: 22px;
    height: 22px;
}

.time {
    margin-left: 15px;
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 12px;
    color: gray;
    border-bottom: 1px solid rgb(224, 224, 224);
    width: 100%;
    display: flex;
    align-items: center;
    white-space: nowrap;
    justify-content: space-between;
}

.eDataList {
    display: flex;
    align-items: flex-start;
    padding: 5px 30px;
    margin: 3px 0px;
    position: relative;
}

.eDataList::after {
    position: absolute;
    content: "";
    width: calc(100% - 60px);
    height: 1px;
    bottom: 0;
    border-bottom: 1px solid #eee;
    padding: 1px;
    margin-right: 30px;
}

.eDataList:hover {
    background: #eee;
}

.dataTitle {
    font-size: 13px;
    color: #1f1f1f;
    display: flex;
    min-height: 22px;
}

.dataTitle>span {
    white-space: nowrap;
    max-height: 17px;
}

.dataHead {
    background: rgb(238, 238, 238);
    margin-top: 0px;
    position: sticky;
    top: 0;
    z-index: 1;
}

.dataDom {
    flex: 1;
    text-align: left;
    padding: 10px 0;
    display: flex;
    justify-content: center;
    font-size: 13px;
}

.dataDom:first-child {
    justify-content: flex-start;
}

.dataDom:last-child {
    justify-self: flex-end;
}
</style>